<!-- 我的审核 -->
<template lang="html">
  <Tabs :value="tab_name" @on-click="changeTabs">
    <TabPane label="正在审核" name="审核中">
      <Card :bordered="false">
        <p slot="title">正在审核</p>
        <p>
          <Table border :columns="zzsh_columns" :data="list_datas" :loading="list_load"></Table>
        </p>
        <Row style="padding:10px 0">
          <Col span="24">
          <Page style="float:right" :total="page_total" :current="page_current" :page-size="page_size" show-total
            @on-change="changePage" @on-page-size-change="changePageSize" />
          </Col>
        </Row>
      </Card>
    </TabPane>
    <TabPane label="已审核" name="已审核">
      <card>
        <p slot="title">已审核</p>
        <Row>
          <Col span="2">
          <h3>审核日期</h3>
          </Col>
          <Col span="3">
          <DatePicker  type="date" placeholder="开始时间"></DatePicker >
          </Col>
          <Col span="3">
          <DatePicker  type="daterange" placement="bottom-end" placeholder="结束时间"></DatePicker >
          </Col>
          <Col style="border:1px #e8eaec solid;text-align: center;padding:5px 0" span="4">总计</Col>
          <Col style="border:1px #e8eaec solid;text-align: center;padding:5px 0" span="4">30个报告书20个报告表</Col>
          <Col style="border:1px #e8eaec solid;text-align: center;padding:5px 0" span="4">绩效8000</Col>
        </Row>
        <Table border :columns="ysh_columns" :data="list_datas" :loading="list_load" style="margin-top: 10px"></Table>
        <Row style="padding:10px 0">
          <Col span="24">
          <Page style="float:right" :total="page_total" :current="page_current" :page-size="page_size" show-total
            show-elevator show-sizer @on-change="changePage" @on-page-size-change="changePageSize" />
          </Col>
        </Row>
      </card>
    </TabPane>
  </Tabs>
</template>

<script>
  export default {
    data() {
      return {
        tab_name: '审核中',
        zzsh_columns: [{
            align: 'center',
            title: '项目编号',
            key: 'project_number'
          },
          {
            align: 'center',
            title: '项目名称',
            key: 'project_name'
          },
          {
            align: 'center',
            title: '公司级别',
            key: 'Project_level_name'
          },
          {
            align: 'center',
            title: '状态',
            key: 'audit_type'
          },
          {
            align: 'center',
            title: '操作',
            render: (h, params) => {
              return h("div", [
                h("Button", {
                    props: {
                      type: "primary",
                      size: "small"
                    },
                    style: {
                      marginRight: "5px",
                      color: "#ffffff",
                      background: "#2996ff",
                      border: "none",
                      padding: "0px 5px"
                    },
                    on: {
                      click: () => {
                        this.toShow(params.row.project_id)
                      }
                    }
                  },
                  '查看'
                ),
                h("Button", {
                    props: {
                      type: "primary",
                      size: "small"
                    },
                    style: {
                      marginRight: "5px",
                      color: "#ffffff",
                      background: "#19be6b",
                      border: "none",
                      padding: "0px 5px"
                    },
                    on: {
                      click: () => {
                        // 审核
                        console.log(params.row)
                        this.audit(params.row.id, params.row.audit_type, params.row.pid)
                      }
                    }
                  },
                  '审核'
                )
              ])
            }
          },
        ],

        ysh_columns: [{
            title: '序号',
            type: 'index',
            align: 'center'
          },
          {
            title: '项目编号',
            key: 'project_number',
            align: 'center'
          },
          {
            title: '项目名称',
            key: 'project_name',
            align: 'center'
          },
          {
            title: '公司级别',
            key: 'Project_level',
            align: 'center'
          },
          {
            title: '报告类型',
            key: 'report_type',
            align: 'center'
          },
          {
            title: '审批部门',
            key: 'Approval_unit',
            align: 'center'
          },
          {
            title: '状态',
            key: 'stats',
            align: 'center'
          },
          {
            title: '审核日期',
            key: 'audit_time',
            align: 'center'
          },
          {
            title: '审核绩效',
            key: 'Audit_score',
            align: 'center'
          },
          {
            title: '操作',
            align: 'center',
            render: (h, params) => {
              return h("div", [
                h("Button", {
                    props: {
                      type: "primary",
                      size: "small"
                    },
                    on: {
                      click: () => {
                        this.toShow(params.row.project_id)
                      }
                    }
                  },
                  '查看'
                )
              ])
            }
          }
        ],

        list_datas: [],
        list_load: true,
        page_total: 0,
        page_current: 1,
        page_size: 10,
      }
    },
    mounted() {
      // 判断是否存返回而来
      let info = this.$store.state.myProjectCheck
      if (info.tab_name) {
        this.tab_name = info.tab_name
        this.page_size = info.page_size
        this.getList(info.page_current)

        console.log('fault的哎对飞按时地方');
      } else {
        this.getList(1)
      }

    },
    methods: {
      getList(page) {
        this.list_load = true
        axios.get('/audit/findByAuditor', {
          params: {
            Stats: this.tab_name,
            PageIndex: page,
            PageSize: this.page_size,
            Auditor: 18,
          }
        }).then((res) => {
          this.page_current = page
          this.page_total = res.count
          this.list_datas = res.data
          let list_datas = this.list_datas
          console.log(this.list_datas)
          list_datas.forEach(e => {
            if (e.Project_level == 0) {
              e['Project_level_name'] = '总公司'
            } else {
              e['Project_level_name'] = '分公司'
            }
          });


          this.list_load = false
        }).catch(err => {
          alert('崩了')
        })
      },
      changePage(page) {
        this.page_current = page
        this.getList(page)
      },
      changePageSize(size) {
        this.page_size = size
        this.getList(1)
      },
      changeTabs(tab_name) {
        this.tab_name = tab_name
        this.list_load = true
        this.page_current = 1
        this.page_total = 0
        this.getList(1)
      },
      toShow(project_id) {
        // 保存 当前详情
        this.$store.commit('setMyProjectCheck', {
          project_id,
          tab_name: this.tab_name,
          page_size: this.page_size,
          page_current: this.page_current,
        })

        this.$router.push({
          name: 'rojectProcedures',
          query: {
            project_id,
          }
        })
      },
      //跳转对应审核
      audit(id, Atype, Project_id) {
        let route_name = ''
        switch (Atype) {
          case '分公司一审':
            route_name = 'myFirstInstance'
            Atype = 0
            break;
          case '分公司二审':
            route_name = 'mySecondInstance'
            Atype = 1
            break;
          case '初审':
            route_name = 'myfirstTrial'
            Atype = 2
            break;
          case '复审':
            route_name = 'myrEexamine'
            Atype = 3
            break;
          case '终审':
            route_name = 'mylast'
            Atype = 4
            break;
          default:
            console.log(Atype)
            return
        }

        axios.get('audit/isChange', {
          params: {
            Id: id
          }
        }).then(res => {
          console.log(res)
          if (res.stats == "0") {
            // 审核页
            this.$router.push({
              name: route_name,
              query: {
                Project_id,
                Atype,
                id,
              }
            })
          } else {
            // 审核修改页
            this.$router.push({
              name: route_name + 'Modification',
              query: {
                Project_id,
                Atype,
                id,
              }
            })
          }

        }).catch(err => {
          alert('请求崩溃')
        })
      }
    },
  }
</script>

<style lang="css">
</style>